/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mobilface.mingle;

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author josh.newnham
 */
public class MobileMidlet extends MIDlet implements Constants {
    private Image _imgLoading;
    private Image _imgShade;
    
    private Controller _controller = null; 
    
    protected void startApp() throws MIDletStateChangeException {
        
        if( _controller == null ){
            loadImages(); 
            _controller = new Controller( this, _imgShade, _imgLoading, MISC_LOADING_ANIM_FRAME_W, MISC_LOADING_ANIM_FRAME_H, 
                    MISC_LOADING_ANIM_FRAME_TIME, Constants.MISC_SCREEN_WIDTH, Constants.MISC_SCREEN_HEIGHT );
            
            Display.getDisplay( this ).setCurrent( _controller );
            
            try{
                _controller.initResources();
            }
            catch( Exception e ){
                System.err.println( e.toString() );
                e.printStackTrace(); 
            }                
        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
    
    /** loads images required for the controller */ 
    private void loadImages(){
        try{
            _imgShade = Image.createImage( IMG_PATH_SHADING );
            _imgLoading = Image.createImage( IMG_PATH_LOADING );
        }
        catch( IOException ioe ){
            System.out.println( "WidgetTest.loadImages; error loading images. " + ioe.toString() );
        }
    }
}
